using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using ACME.Northwind.Service.Interfaces;
using ACME.Northwind.MockProxy.EventArgs;

namespace ACME.Northwind.MockProxy
{
	/// <summary>
	/// The service implementation for Supplier object
	/// </summary>
	public partial class SupplierService : ISupplierService
	{
		#region ISupplierService Members

		/// <summary>
		/// Run the mock for the select by the primary key
		/// </summary>
		public SupplierDTO SelectByPrimaryKey(int supplierid)
		{
			SupplierPrimaryKeyEventArgs eventArgs = new SupplierPrimaryKeyEventArgs(supplierid);
			this.OnMockSupplierSelectByPrimaryKey(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select all
		/// </summary>
		public List<SupplierDTO> RunSelect()
		{
			SupplierRunSelectEventArgs eventArgs = new SupplierRunSelectEventArgs();
			this.OnMockSupplierRunSelect(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select with LINQ
		/// </summary>
		public List<SupplierDTO> RunSelect(string linq)
		{
			SupplierRunSelectLINQEventArgs eventArgs = new SupplierRunSelectLINQEventArgs(linq);
			this.OnMockSupplierRunSelectLINQ(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for paged select
		/// </summary>
		public PagedQueryResults<SupplierDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			SupplierRunSelectPagedEventArgs eventArgs = new SupplierRunSelectPagedEventArgs(pageIndex, pageSize, ascending, sortColumn, linq);
			this.OnMockSupplierRunSelectPaged(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Return a list of related Product objects
		/// </summary>
		public List<ProductDTO> GetProductList(SupplierDTO item)
		{
			SupplierDTOEventArgs eventArgs = new SupplierDTOEventArgs(item);
			this.OnMockGetProductList(eventArgs);
			List<ProductDTO> retval = new List<ProductDTO>();
			retval.AddRange(eventArgs.ReturnDTOList.Select(x => (ProductDTO)x));
			return retval;
		}

		/// <summary>
		/// Persists a single item
		/// </summary>
		public bool Persist(SupplierDTO dto)
		{
			SupplierPersistEventArgs eventArgs = new SupplierPersistEventArgs(dto);
			this.OnMockSupplierPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Persists a list
		/// </summary>
		public bool Persist(List<SupplierDTO> list)
		{
			SupplierPersistEventArgs eventArgs = new SupplierPersistEventArgs(list);
			this.OnMockSupplierPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Delete a single item
		/// </summary>
		public bool Delete(SupplierDTO dto)
		{
			SupplierDeleteEventArgs eventArgs = new SupplierDeleteEventArgs(dto);
			this.OnMockSupplierDelete(eventArgs);
			return eventArgs.ReturnValue;
		}

		#endregion

		#region Supplier Events

		partial void GetSelectByPrimaryKey();

		/// <summary>
		/// The event for the SelectByPrimaryKey method
		/// </summary>
		public event EventHandler<SupplierPrimaryKeyEventArgs> MockSupplierSelectByPrimaryKey;

		/// <summary>
		/// Raises the OnMockRegistrationCodeSelectByPrimaryKey event
		/// </summary>
		protected virtual void OnMockSupplierSelectByPrimaryKey(SupplierPrimaryKeyEventArgs e)
		{
			if (this.MockSupplierSelectByPrimaryKey != null)
				this.MockSupplierSelectByPrimaryKey(this, e);
		}

		/// <summary>
		/// The event for the RunSelect method
		/// </summary>
		public event EventHandler<SupplierRunSelectEventArgs> MockSupplierRunSelect;

		/// <summary>
		/// Raises the OnMockRunSelect event
		/// </summary>
		protected virtual void OnMockSupplierRunSelect(SupplierRunSelectEventArgs e)
		{
			if (this.MockSupplierRunSelect != null)
				this.MockSupplierRunSelect(this, e);
		}

		/// <summary>
		/// The event for the RunSelectLINQ method
		/// </summary>
		public event EventHandler<SupplierRunSelectLINQEventArgs> MockSupplierRunSelectLINQ;

		/// <summary>
		/// The event for the OnMockRunSelectLINQ method
		/// </summary>
		protected virtual void OnMockSupplierRunSelectLINQ(SupplierRunSelectLINQEventArgs e)
		{
			if (this.MockSupplierRunSelectLINQ != null)
				this.MockSupplierRunSelectLINQ(this, e);
		}

		/// <summary>
		/// The event for the RunSelectPaged method
		/// </summary>
		public event EventHandler<SupplierRunSelectPagedEventArgs> MockSupplierRunSelectPaged;

		/// <summary>
		/// The event for the OnMockRunSelectPaged method
		/// </summary>
		protected virtual void OnMockSupplierRunSelectPaged(SupplierRunSelectPagedEventArgs e)
		{
			if (this.MockSupplierRunSelectPaged != null)
				this.MockSupplierRunSelectPaged(this, e);
		}

		/// <summary>
		/// The event for the GetProductList method
		/// </summary>
		public event EventHandler<SupplierDTOEventArgs> MockGetProductList;

		/// <summary>
		/// The event for the OnMockGetProductList method
		/// </summary>
		protected virtual void OnMockGetProductList(SupplierDTOEventArgs e)
		{
			if (this.MockGetProductList != null)
				this.MockGetProductList(this, e);
		}

		/// <summary>
		/// The event for the Persist method
		/// </summary>
		public event EventHandler<SupplierPersistEventArgs> MockSupplierPersist;

		/// <summary>
		/// Raises the OnMockPersist event
		/// </summary>
		protected virtual void OnMockSupplierPersist(SupplierPersistEventArgs e)
		{
			if (this.MockSupplierPersist != null)
				this.MockSupplierPersist(this, e);
		}

		/// <summary>
		/// The event for the Delete method
		/// </summary>
		public event EventHandler<SupplierDeleteEventArgs> MockSupplierDelete;

		/// <summary>
		/// Raises the OnMockDelete event
		/// </summary>
		protected virtual void OnMockSupplierDelete(SupplierDeleteEventArgs e)
		{
			if (this.MockSupplierDelete != null)
				this.MockSupplierDelete(this, e);
		}

		#endregion

	}
}
